package com.lineage.server.serverpackets;

import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1ItemStatus;
import java.util.Iterator;
import java.util.List;

public class S_InvList extends ServerBasePacket {
  private byte[] _byte;
  
  public S_InvList(List<L1ItemInstance> items) {
    this._byte = null;
    writeC(5);
    writeC(items.size());
    Iterator<L1ItemInstance> iterator = items.iterator();
    while (iterator.hasNext()) {
      L1ItemInstance item = iterator.next();
      writeD(item.getId());
      switch (item.getItem().getItemId()) {
        case 40318:
          writeH(166);
          break;
        case 40319:
          writeH(569);
          break;
        case 40321:
          writeH(837);
          break;
        case 49158:
          writeH(3674);
          break;
        case 49157:
          writeH(3605);
          break;
        case 49156:
          writeH(3606);
          break;
        default:
          writeH(0);
          break;
      } 
      int type = item.getItem().getUseType();
      if (type < 0)
        type = 0; 
      writeC(type);
      if (item.getChargeCount() <= 0) {
        writeC(0);
      } else {
        writeC(item.getChargeCount());
      } 
      writeH(item.get_gfxid());
      writeC(item.getBless());
      writeD((int)Math.min(item.getCount(), 2000000000L));
      writeC(item.getItemStatusX());
      writeS(item.getViewName());
      if (!item.isIdentified()) {
        writeC(0);
      } else {
        L1ItemStatus itemInfo = new L1ItemStatus(item);
        byte[] status = itemInfo.getStatusBytes(false).getBytes();
        writeC(status.length);
        byte[] array;
        int length = (array = status).length;
        int i = 0;
        while (i < length) {
          byte b = array[i];
          writeC(b);
          i++;
        } 
      } 
      writeC(10);
      writeH(0);
      writeD(0);
      writeD(0);
    } 
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
